﻿using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


namespace VITCS.FCViewWebPart
{
    [Guid("8debf379-620b-4e19-8230-0a41782c2ce7")]
    public class FCViewWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {

        string filePath = "";
        [WebBrowsable(true), WebDisplayName("File Path"), WebDescription("Enter the file path"), Personalizable(PersonalizationScope.Shared)]
        public String FilePath { get { return filePath; } set { filePath = value; } }

        public FCViewWebPart()
        {
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            // TODO: add custom rendering code here.
            Label label = new Label();
            //label.Text = "Hello World";
            if (!string.IsNullOrEmpty(this.filePath))
                label.Text = GetFileContents(this.FilePath);
            else
                label.Text = "Set web part's file path property";
            this.Controls.Add(label);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="FullPath"></param>
        /// <returns></returns>
        public string GetFileContents(string FullPath)
        {

            string strContents = null;
            StreamReader objReader = default(StreamReader);
            try
            {
                objReader = new StreamReader(FullPath);
                strContents = objReader.ReadToEnd();
                objReader.Close();
                return strContents;
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

    }
}
